<!DOCTYPE html>
<html>

<?php
include './head/connect.php';
?>

<body>


<h1>用于读取数据库AGV设备数据</h1>

<?php
echo"Hello php!";
?>

<?php
$dbhost = '10.68.2.32';  // mysql服务器主机地址
$dbuser = 'wms';            // mysql用户名
$dbpass = 'CCshenda889';          // mysql用户名密码
$conn = mysqli_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
    die('Could not connect: ' . mysqli_error());
}
echo '数据库连接成功！';

//创建数据库

// $sql = 'CREATE DATABASE RUNOOB';
// $retval = mysqli_query($conn,$sql );
// if(! $retval )
// {
//     die('创建数据库失败: ' . mysqli_error($conn));
// }
// echo "数据库 RUNOOB 创建成功\n";






//创建数据表
// CREATE TABLE IF NOT EXISTS `runoob_tbl`(
//     `runoob_id` INT UNSIGNED AUTO_INCREMENT,
//     `runoob_title` VARCHAR(100) NOT NULL,
//     `runoob_author` VARCHAR(40) NOT NULL,
//     `submission_date` DATE,
//     PRIMARY KEY ( `runoob_id` )
//  )ENGINE=InnoDB DEFAULT CHARSET=utf8;

//读取

$sql='SELECT * FROM `agv_robot`';
mysqli_select_db($conn, 'wms' );//选择数据库
$retval = mysqli_query( $conn, $sql );
if(! $retval )
{
    die('无法读取数据: ' . mysqli_error($conn));
}

// 设置编码，防止中文乱码
mysqli_query($conn , "set names utf8");

echo '<h2> MySQL WHERE 子句测试<h2>';
echo '<table border="1"><tr><td>ID</td><td>设备序列号</td><td>设备IP</td><td>设备型号</td></tr>';
while($row = mysqli_fetch_array($retval, MYSQLI_ASSOC))
{
    echo "<tr><td> {$row['ID']}</td> ".
         "<td>{$row['DEVICE_CODE']} </td> ".
         "<td>{$row['DEVICE_IP']} </td> ".
         "<td>{$row['DEVICETYPE']} </td> ".
         "</tr>";
}



//释放内存
mysqli_free_result($retval);
mysqli_close($conn);
?>
</body>
</html>